home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10058 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with writing floating points numbers to strings
  5. Date: 14 Mar 1996 21:27 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <14MAR199621272391@erich.triumf.ca>
  9. References: <4ia9g9$d1f@yama.mcc.ac.uk>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4ia9g9$d1f@yama.mcc.ac.uk>, Simon Letherman <simon@ma.man.ac.uk> writes...
  14.  
  15. >I want to write output to a large string, which I can then get Mathematica
  16. >to use to draw a graph. Unfortunately, this means that I've got to store
  17. >floating point (actually double) variables in string format, and it
  18. >really doesn't want to. I can usually get my code past the preprocessor,
  19. >but when running anything like
  20. >    sprintf(string, "%lf", &double);
  21. >I get the core dumped on me.
  22.  
  23. use
  24.     sprintf(string, "%f", double);
  25.  
  26. A float argument passed to (s|f)printf() is automatically promoted to double,
  27. so there is no distinction between float and double - %f is used to print
  28. either.  %lf is an error (but may be accepted bu some lenient compilers...)
  29.  
  30. Your real problem was the "&double" - you don't want the "&".  printf() wants
  31. to get the variables themselves, not their addresses.
  32.  
  33. The parameters to scanf() and printf() are similar, but not identical!
  34.  
  35.  
  36. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  37. Internet: bennett@triumf.ca         | of one another only when one can be
  38. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  39. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  40. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  41. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  42.  
  43.